package com.example.administrator.z.ui;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.content.ContextCompat;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.widget.LinearLayout;
import android.widget.ListAdapter;
import android.widget.ListView;


import com.example.administrator.z.R;
import com.example.administrator.z.adapter.SchoolNoticeAdapter;
import com.example.administrator.z.entity.NoticeData;
import com.example.administrator.z.fragment.HomeWorkFragment;
import com.example.administrator.z.fragment.SchoolNoticeFragment;

import java.util.ArrayList;
import java.util.List;

public class SchoolMessageActivity extends AppCompatActivity {

    private List<String> mTitle;
    private TabLayout tabLayout;
    private ViewPager mViewPager;
    private List<Fragment> mFragment;


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_school);
        tabLayout= (TabLayout) findViewById(R.id.tabLayout);

        //tabLayout.addTab(tabLayout.newTab().setText("校方通知"));

      //  tabLayout.addTab(tabLayout.newTab().setText("作业通知"));
        //设置TabLayout的模式

        initData();

        LinearLayout linearLayout = (LinearLayout) tabLayout.getChildAt(0);
        linearLayout.setShowDividers(LinearLayout.SHOW_DIVIDER_MIDDLE);
        linearLayout.setDividerDrawable(ContextCompat.getDrawable(this,
                R.drawable.divider));

        tabLayout.setTabMode(TabLayout.MODE_FIXED);
        mViewPager = (ViewPager) findViewById(R.id.mViewPager);
        mViewPager.setOffscreenPageLimit(mFragment.size());
        mViewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int i) {

            }

            @Override
            public void onPageScrollStateChanged(int i) {

            }
        });

        mViewPager.setAdapter(new FragmentPagerAdapter(getSupportFragmentManager()) {
            @Override
            public Fragment getItem(int position) {
                return mFragment.get(position);
            }

            @Override
            public int getCount() {
                return mFragment.size();
            }

            //设置标题
            @Override
            public CharSequence getPageTitle(int position) {
                return mTitle.get(position);
            }
        });

        tabLayout.setupWithViewPager(mViewPager);

    }

    private void initData() {
        mTitle = new ArrayList<>();
        mTitle.add("校方通知");
        mTitle.add("作业通知");

        mFragment = new ArrayList<>();
        mFragment.add(new SchoolNoticeFragment());
        mFragment.add(new HomeWorkFragment());
    }


}


